﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace SksApp
{
    public partial class Pinpad : UserControl
    {
        public enum GirisTipi
        {
            SifreGirisi
        }

        private GirisTipi _girisTipi = GirisTipi.SifreGirisi;
        public GirisTipi SifreGirisi { get { return _girisTipi; } set { _girisTipi = value; } }

        public delegate void MessageHandler(string senderText);
        public event MessageHandler MessageReceived;

        public Pinpad()
        {
            InitializeComponent();
            switch (_girisTipi)
            {
                case GirisTipi.SifreGirisi:
                    txtGiris.PasswordChar = '*';
                    break;
                default:
                    break;
            }
        }

        private void btnClick(object sender, EventArgs e)
        {
            Button btn = sender as Button;
            switch (btn.Text)
            {
                case "Sil":
                    txtGiris.Text = "";
                    break;
                case "Giriş":
                    if (MessageReceived != null)
                        MessageReceived(txtGiris.Text);
                    break;
                default:
                    txtGiris.Text += btn.Text;
                    break;
            }
            txtGiris.Select(txtGiris.TextLength, 0);
        }

        private void btnKapat_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void txtGiris_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                if (MessageReceived != null)
                    MessageReceived(txtGiris.Text);
            }
        }
    }
}
